package com.example.database.controller;

import com.example.database.ado.JpaUserRepository;
import com.example.database.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class JpaController {
    @Autowired
    private JpaUserRepository userRepository;


    @GetMapping("/getUser")
    public User GetUser(@RequestParam(required = true,defaultValue = "1") Long id) {
        User result= userRepository.findById(id).orElseGet(() -> new User());
        if(result==null)
            return new User();
        return result;
    }
}
